﻿<?php
class SearchspController extends Zend_Controller_Action
{
	public function searchAction()
	  {
	   $model= new Model_Product();
	   $cat=$model->getCatID();
	   $i=0;
	   $a=array();
	   foreach($cat as $x)
	   {
	     $a[$i]=$x['cat_id'];
		 $i++;
	   
	   }
	   $model= new Model_Category();
	   $catname=$model->getCatnamebycatID($a);
	   $this->view->catth=$catname;
	    
	  } 
	public function getvalueAction()
	{
		$giatu=(int)($_GET['giatu']);
		$dengia=(int)($_GET['dengia']);
		$tukhoa=$_GET['tukhoa'];
		
		$loaisp=(int)$_GET['loaisp'];
		//var_dump($loaisp);
		if($giatu>$dengia){
			echo "Không có sản phẩm nào phù hợp yêu cầu!";
			break;
		}
		else
		{
	       
			$modelProduct=new Model_Product();
			if( $giatu ==NULL && $dengia==NULL && $loaisp==NULL ){
				$timthay=$modelProduct->getproductbyfindnocatnoprice($tukhoa);
			} elseif ($giatu ==NULL &&$dengia==NULL && $loaisp!=NULL ){
			        $timthay=$modelProduct->getproductbyfindnoprice($loaisp,$tukhoa);
			
			}
			elseif($loaisp==NULL && $giatu !=NULL && $dengia!=NULL ) {
				$timthay=$modelProduct->getproductbyfindnocat($giatu,$dengia,$tukhoa);
			
			}
			else
			{
			$timthay=$modelProduct->getproductbyfind($giatu,$dengia,$loaisp,$tukhoa);
			
			}
			$this->view->sl=count($timthay);
			if (count($timthay)>0){
				$pageNumber = 4 ; //or whatever you wish
				$itemNumber = 6; //or whatever you wish
				$paginator = Zend_Paginator::factory($timthay);
			
				$paginator->setItemCountPerPage($itemNumber);
				$paginator->getItemsByPage($pageNumber);
				$paginator->setCurrentPageNumber($this->_getParam('page'));
				Zend_Paginator::setDefaultScrollingStyle('Sliding');
				$view = new Zend_View();
				$paginator->setView($view);
				
				//this are your results from db        
				$this->view->timthay = $paginator;
				//echo count($paginator);
				//this is paginator
				$this->view->paginator = $paginator;
			}
			else{
				//$this->view->msg="khong ton tai";
			    }

		}
		
	}
}